package com.hp.ssm.controller;

import com.hp.ssm.pojo.User;
import com.hp.ssm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * 用户的控制器
 * 查询所有用户  http://localhost:8080/users  GET
 * 查询单用户  http://localhost:8080/user/1  GET
 * 添加用户  http://localhost:8080/user  POST
 * 更新用户  http://localhost:8080/user  PUT
 * 删除用户  http://localhost:8080/user/1  DELETE
 */
@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("users")
    public String findAll(Model model){
        List<User> users = userService.findAll();
        model.addAttribute("users",users);
        return "user-list";
    }
}
